Skip to content

fix: skip -march auto-detection for cross-compilation presets#21356

Merged
alexghr merged 1 commit intomerge-train/spartanfrom
claudebox/fix-merge-train-spartan-ci
Mar 17, 2026
Merged

fix: skip -march auto-detection for cross-compilation presets#21356
alexghr merged 1 commit intomerge-train/spartanfrom
claudebox/fix-merge-train-spartan-ci

Conversation

@AztecBot
Copy link
Collaborator

@AztecBot AztecBot commented Mar 11, 2026

Summary

Fixes CI failure on merge-train/spartan caused by -march=skylake being injected into aarch64 cross-compilation builds (arm64-android, arm64-ios, arm64-macos).

Root cause: The arch.cmake auto-detection added in #21611 defaults TARGET_ARCH to skylake when ARM is not detected. Cross-compile presets (ios, android) don't set CMAKE_SYSTEM_PROCESSOR, so ARM detection fails and -march=skylake gets passed to aarch64 Zig builds — which errors with unknown CPU: 'skylake'. For arm64-macos, -march=generic overrides Zig's -mcpu=apple_a14, breaking libdeflate.

Fix: Gate auto-detection on NOT CMAKE_CROSSCOMPILING. Cross-compile toolchains handle architecture targeting via their own flags (e.g. Zig -mcpu). Presets that explicitly set TARGET_ARCH (amd64-linux, arm64-linux) are unaffected.

Also restores native_build_dir variable dropped in the build infrastructure refactor.

Test plan

  • Verified all cross-compile presets (arm64-android, arm64-ios, arm64-ios-sim, arm64-macos, x86_64-android) configure with zero -march flags
  • Verified native presets (default, amd64-linux, arm64-linux) still get correct -march values

@AztecBot AztecBot added the claudebox Owned by claudebox. it can push to this PR. label Mar 11, 2026
@AztecBot AztecBot force-pushed the claudebox/fix-merge-train-spartan-ci branch from 689d65d to 4278757 Compare March 11, 2026 13:38
@AztecBot AztecBot changed the title fix(p2p): stabilize flaky rate limit test in reqresp fix: remove obsolete KVArchiverDataStore constructor arg in test Mar 11, 2026
@AztecBot AztecBot force-pushed the claudebox/fix-merge-train-spartan-ci branch from 4278757 to c376ade Compare March 11, 2026 15:24
@AztecBot AztecBot changed the title fix: remove obsolete KVArchiverDataStore constructor arg in test chore: add e2e_deploy_contract/deploy_method.test.ts to flaky test patterns Mar 11, 2026
@AztecBot AztecBot force-pushed the claudebox/fix-merge-train-spartan-ci branch from c376ade to 06b1d54 Compare March 16, 2026 10:42
@AztecBot AztecBot changed the title chore: add e2e_deploy_contract/deploy_method.test.ts to flaky test patterns fix: respect CPUS env var in browser tests and add flake pattern Mar 16, 2026
@AztecBot AztecBot force-pushed the claudebox/fix-merge-train-spartan-ci branch from 06b1d54 to 41a28fe Compare March 17, 2026 09:22
@AztecBot AztecBot changed the title fix: respect CPUS env var in browser tests and add flake pattern fix: skip -march auto-detection for cross-compilation presets Mar 17, 2026
@AztecBot AztecBot force-pushed the claudebox/fix-merge-train-spartan-ci branch from 41a28fe to 423a8b0 Compare March 17, 2026 10:00
@alexghr alexghr marked this pull request as ready for review March 17, 2026 10:14
@AztecBot AztecBot force-pushed the claudebox/fix-merge-train-spartan-ci branch from 423a8b0 to c308c01 Compare March 17, 2026 10:22
@AztecBot AztecBot changed the title fix: skip -march auto-detection for cross-compilation presets fix: restore NOT ARM guard in arch.cmake for cross-compilation Mar 17, 2026
The arch.cmake auto-detection (added in #21611) defaults TARGET_ARCH to
'skylake' when ARM is not detected. For cross-compilation presets like
arm64-ios, arm64-android, and arm64-ios-sim, CMAKE_SYSTEM_PROCESSOR is
not set, so ARM detection fails and -march=skylake gets injected into
aarch64 builds — causing zig to error with 'unknown CPU: skylake'.

For arm64-macos, ARM is detected but -march=generic overrides zig's
-mcpu=apple_a14, causing libdeflate build failures (missing AES target
feature).

Fix: gate auto-detection on NOT CMAKE_CROSSCOMPILING. Cross-compile
toolchains (Zig) handle architecture targeting via their own flags.
Presets that explicitly set TARGET_ARCH (amd64-linux, arm64-linux) are
unaffected.

Also restores native_build_dir variable that was dropped in the build
infrastructure refactor.
@AztecBot AztecBot force-pushed the claudebox/fix-merge-train-spartan-ci branch from c308c01 to 8f1c6d9 Compare March 17, 2026 11:03
@AztecBot AztecBot changed the title fix: restore NOT ARM guard in arch.cmake for cross-compilation fix: skip -march auto-detection for cross-compilation presets Mar 17, 2026
@alexghr alexghr removed the claudebox Owned by claudebox. it can push to this PR. label Mar 17, 2026
@alexghr alexghr merged commit 08b84e8 into merge-train/spartan Mar 17, 2026
14 checks passed
@alexghr alexghr deleted the claudebox/fix-merge-train-spartan-ci branch March 17, 2026 11:54
ludamad pushed a commit that referenced this pull request Mar 17, 2026
# fix: ARM64 devcontainer builds — skip `-march` on ARM and use explicit
zig aarch64 target

## Summary

Fixes SIGILL (Illegal Instruction) crashes and build failures on ARM64
Mac (M3/Apple Silicon) devcontainers caused by incorrect `-march`
handling introduced in #21611.

## Problem

PR #21611 originally fixed ARM64 devcontainer builds by using explicit
`aarch64-linux-gnu.2.35` zig targets. During the merge, that approach
was replaced with cmake-based auto-detection that sets
`TARGET_ARCH=generic` on ARM and passes `-march=generic` to the
compiler. This caused two distinct failures:

### 1. SIGILL crashes (`Illegal instruction`)

The zig compiler wrappers still used `-target native-linux-gnu.2.35`,
which auto-detects the host CPU. On CI (AWS Graviton with SVE
extensions), this produces binaries containing SVE instructions. These
cached binaries are then downloaded on Apple Silicon devcontainers
(ARM64 without SVE), causing SIGILL when executed — e.g.
`honk_solidity_key_gen` crashing during `barretenberg/sol` bootstrap.

The `-march=generic` flag was supposed to override this, but
`-march=generic` is **not a valid value on aarch64**. It's an x86
concept. LLVM/zig silently ignored it, so the native CPU detection still
produced SVE instructions.

### 2. Build failures (`unknown CPU: 'armv8'`)

Even attempting `-march=armv8-a` (a valid GCC/Clang aarch64 value) fails
because zig uses its own CPU naming scheme (e.g. `generic`,
`cortex_a72`, `apple_m3`), not GCC-style architecture strings. Zig
interprets `-march=armv8-a` as CPU name `armv8`, which doesn't exist →
`error: unknown CPU: 'armv8'`.

**Bottom line:** The `-march` cmake approach fundamentally doesn't work
with zig on ARM. Zig has its own architecture targeting via `-target`,
which is the correct mechanism.

## What this PR changes

### 1. `arch.cmake` — Skip `-march` auto-detection on ARM

Removed the ARM branch from the auto-detection. On x86_64, we still
auto-detect `TARGET_ARCH=skylake`. On ARM, we don't set `TARGET_ARCH` at
all, so no `-march` flag is passed — the zig wrappers handle
architecture targeting instead.

### 2. `zig-cc.sh` / `zig-c++.sh` — Explicit aarch64 target on ARM Linux

Restored the original fix from #21611 that was dropped during merge. On
ARM64 Linux, the wrappers now use `-target aarch64-linux-gnu.2.35`
instead of `-target native-linux-gnu.2.35`. This produces generic ARM64
code without CPU-specific extensions (SVE, etc.), ensuring cached
binaries work on all ARM64 machines — Graviton, Apple Silicon, Ampere,
etc.

x86_64 behavior is unchanged (still uses `-target native`).

## Context: what happened after #21611

After #21611 merged with the cmake auto-detection approach, it triggered
a cascade of follow-up PRs trying to fix the fallout:

| PR | Status | Issue |
|----|--------|-------|
| #21621 | Merged | Introduced the auto-detect approach (replaced zig
wrapper fix with cmake `-march`) |
| #21356 | Merged | Added `NOT CMAKE_CROSSCOMPILING` guard for
cross-compile failures |
| #21637 | Open | Attempting to fix cross-compiles + restore
`native_build_dir` |
| #21660 | Open | Attempting to fix cross-compile targets |
| #21632 | Open | Attempting to fix cross-compile targets |
| #21662 | Open | Adding `CMAKE_SYSTEM_PROCESSOR` to ARM64 cross-compile
presets |
| #21653 | Open | Attempting to skip auto-detection when cross-compiling
|
| #21655 | Open | Attempting to skip auto-detection for
cross-compilation targets |

This PR supersedes the still-open PRs above by addressing the root
cause: `-march` via cmake doesn't work with zig on ARM. The zig
`-target` mechanism is the correct approach.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants